﻿using MangoMes.Commont.DapperHelps;
using MangoMes.Commont.Domain.QRUPC;
using MangoMes.Commont.Domain.SellStocks;
using MangoMes.Commont.DTOs;
using MangoMes.Commont.Infrastructures.Interfaces;
using MangoMes.Write.API.Applications.SellStockSearchWrite;
using MediatR;

namespace MangoMes.Write.API.Applications.QRUPCWrite
{
    public class QUCodeCreateHandler : IRequestHandler<QUCodeCreateCommand, ResultsDTO>
    {
        private readonly IBateRepository<QUCode> _qucodeRepository;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="qucodeRepository"></param>
        public QUCodeCreateHandler(IBateRepository<QUCode> qucodeRepository)
        {
            _qucodeRepository = qucodeRepository;
        }
        /// <summary>
        /// 赋码管理新增
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<ResultsDTO> Handle(QUCodeCreateCommand request, CancellationToken cancellationToken)
        {
            DapperHelper dapperHelper = new DapperHelper();
            ResultsDTO res = new ResultsDTO { Code = 0 };
            QUCode per = new QUCode();
            per.QUCodeId = request.QUCodeId;
            per.QUCodeFormat = request.QUCodeFormat;
            per.QUCodeType = request.QUCodeType;
            per.ProductManageName = request.ProductManageName;
            per.ProductManageNode = request.ProductManageNode;
            per.QUCodeStart = request.QUCodeStart;
            per.QUCodeMatter = request.QUCodeMatter;
            per.QUCodeRemark = request.QUCodeRemark;
            per.BarCode = request.BarCode;
            string conn = dapperHelper.MangoMesWrite;
            string str = "insert into qucode values(@QUCodeId,@QUCodeFormat,@QUCodeType,@ProductManageName" +
                ",@ProductManageNode,@QUCodeStart,@QUCodeMatter,@QUCodeRemark,@BarCode)";
            res.Code = await _qucodeRepository.Add(str, per, conn);
            return res;
        }
    }
}
